/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */


import java.io.*;
import java.net.*;

import javax.servlet.*;
import javax.servlet.http.*;

/**
 * Open to add a new post to a group page
 * @author Kyu
 */
public class GroupNewPostServlet extends HttpServlet {
   
     String[] topics = {"Photography", "Cooking", "Java"}; 
     //TODO: get it from DB
    
    /** 
    * Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
    * @param request servlet request
    * @param response servlet response
    */
    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
        response.setContentType("text/html;charset=UTF-8");
        PrintWriter out = response.getWriter();
        try {        
            out.println("<html>");
            out.println("<head>");
            out.println("<title>Servlet GroupNewPostServlet</title>");  
            CSSGenerator.generateNewsGroupPopupReplayInlineCSS(out);
                 
            out.println("</head>");
            out.println("<body>");
            //out.println("<h1>Servlet GroupNewPostServlet at " + request.getContextPath () + "</h1>");
            out.println(
            //"<form>" +
            "<center>" +
            "<table height=\"380\" width=\"480\" border=\"0\">" +// style=\"border-color:#336699 \" border=\""+ngroupOuterTableBorderWidth+"\">" +
            "<tr height=\"10\">" +
            "   <td  colspan=\"2\">" +
            "       <p class=\"ngroupMessageLabel\"> " +
            "       Post Section" +     // title
            "       </p>"  +
            "   </td>" +
           
            "   <td colspan=\"2\" align=\"right\">" +
            "<form name=\"newPostForm\" method=\"POST\" action=\"TempServlet?newPost=true" +
            "&" +
            "\">" +
            //"   <input type=\"text\" size=\"72\" name=messageTitle readonly value=\" " +
            "     <select size=\"1\" name=\"sectionSelection\">" 
            );
            
            //generating options:
            for(int i=0; i<topics.length;i++)
            {   
                out.println("<option ");             
                out.println(" value =\"" + topics[i] + "\"> ");
                out.println(topics[i]);// +  request.getParameter("sections") + " " + ngroupSections[i]);
                out.println("</option>");                
            }     
            out.println("</select>");
      
            out.println(        
          
            "   </td>" +
            "</tr>" +
            "<tr height=\"10\" >" +
            "   <td colspan=\"4\">" +
            "       <p class=\"ngroupMessageLabel\"> " +
            "       Title" +     // Message title
            "       </p>"  +
            "   </td>" +
            "<tr height=\"10\">" +
            "   <td colspan=\"4\">" +
            "   <input type=\"text\" size=\"72\"  name=newPostTitle >" +
            "   </td>" +
            "</tr>" +
            "</tr>"+
             
            // Message body
             "<tr height=\"10\" >" +
            "   <td colspan=\"4\">" +
            "       <p class=\"ngroupMessageLabel\"> " +
            "       Text" +    
            "       </p>"  +
            "   </td>" +
            "</tr>"+
            "<tr height=\"40\">" +
            "   <td valign=\"top\" colspan=\"4\">" +
            "   <textarea rows=\"15\" cols=\"56\" " +        
            "    name=newPostBody >" +
            "</textarea>" +
            "   </td>" +
            "</tr>" +
                    
            "<tr height=\"7\" valign=\"top\">" +          //  |
            "   <td width=\"120\" valign=\"middle\">" +   //  | these two needs to be sorted out
            //"   &nbsp" +
            "   <p class=\"copyRight\"> ClassNet© 2007  </p>"  +
            "   </td>" +
            "   <td width=\"120\">&nbsp</td>" +
            "   <td width=\"200\" align =\"right\" valign=\"top\" >"+
           // "<form name=\"replyForm\" method=\"POST\" action=\"PostServlet\">" +
            " <input type=\"submit\" name=\"newPost\" value=\"Post\" >" +//onClick=\"window.close()\">" +
            "</form>" +  // end of the form
          
            "   </td>" +
            "   <td width=\"40\" align =\"right\" valign=\"top\">"+
            "   <button onclick=\"window.close()\">Cancel</button>"+  
            "   </td>" +                    
            "</tr>" +
            "</table>"+
            "</center>"
            
            );
             
            out.println("</body>");
            out.println("</html>");
           
        } finally { 
            out.close();
        }
    } 

    // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
    /** 
    * Handles the HTTP <code>GET</code> method.
    * @param request servlet request
    * @param response servlet response
    */
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
        processRequest(request, response);
    } 

    /** 
    * Handles the HTTP <code>POST</code> method.
    * @param request servlet request
    * @param response servlet response
    */
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
        processRequest(request, response);
        
    }

    /** 
    * Returns a short description of the servlet.
    */
    public String getServletInfo() {
        return "Short description";
    }
    // </editor-fold>
}
